package com.wuyou.simple;

/**
 * 2373. 矩阵中的局部最大值
 */
public class LargestLocal {

    public static void main(String[] args) {
//        int[][] grid = {{1,1,1,1,1},{1,1,1,1,1},{1,1,2,1,1},{1,1,1,1,1},{1,1,1,1,1}};
        int[][] grid = {{20, 8, 20, 6, 16, 16, 7, 16, 8, 10}, {12, 15, 13, 10, 20, 9, 6, 18, 17, 6}, {12, 4, 10, 13, 20, 11, 15, 5, 17, 1}, {7, 10, 14, 14, 16, 5, 1, 7, 3, 11}, {16, 2, 9, 15, 9, 8, 6, 1, 7, 15}, {18, 15, 18, 8, 12, 17, 19, 7, 7, 8}, {19, 11, 15, 16, 1, 3, 7, 4, 7, 11}, {11, 6, 5, 14, 12, 18, 3, 20, 14, 6}, {4, 4, 19, 6, 17, 12, 8, 8, 18, 8}, {19, 15, 14, 11, 11, 13, 12, 6, 16, 19}};

        System.out.println(sol_1(grid));


    }

    public static int[][] sol_1(int[][] grid) {
        int length = grid.length;
        int[][] maxLocal = new int[length - 2][length - 2];

        for (int i = 0; i < length - 2; i++) {
            for (int j = 0; j < length - 2; j++) {
                maxLocal[i][j] = maxSquared(i, j, grid);
            }
        }


        return maxLocal;
    }

    public static int maxSquared(int x, int y, int[][] grid) {
        int max = 0;
        for (int i = x; i < x + 3; i++) {
            for (int j = y; j < y + 3; j++) {
                max = Math.max(max, grid[i][j]);
            }
        }
        return max;
    }
}
